﻿using System;
using IQIGame.Onigao.Game;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;

namespace IQIGame.Onigao.GamePlay
{
    [Serializable]
    public class UnitCameraClip : PlayableAsset, ITimelineClipAsset
    {
        [SerializeField] public string curveConfig;
        [SerializeField] public bool lookTarget;
        [SerializeField] public int effectiveIndex;
        
        public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
        {
            var rPlayable = UnitCameraBehaviour.Create(graph, owner);
            var rEntityDriver = owner.GetComponent<EntityDriver>();
            var rUnit = BattleClientUtil.GetUnitViewByEntityDriver(rEntityDriver);
            UnitCameraBehaviour clone = rPlayable.GetBehaviour();
            if (rUnit != null)
            {
                clone.curvePath = PathConstant.GetBattleCameraCurvePath(rUnit.roleName, this.curveConfig);
            }
            clone.lookTarget = this.lookTarget;
            clone.effectiveIndex = this.effectiveIndex;
            return rPlayable;
        }

        public ClipCaps clipCaps
        {
            get => ClipCaps.None;
        }
    }
}